package com.o2o.app.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.o2o.app.R;
import com.o2o.app.bean.MessageBean;

public class MessageListAdapter extends BaseAdapter {
	private Context context;
	private List<MessageBean> list;
	private Myhold mh = null;
	private int type;

	public MessageListAdapter(Context context, List<MessageBean> list, int type) {
		this.context = context;
		this.list = list;
		this.type = type;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub

		if (arg1 == null) {
			mh = new Myhold();
			arg1 = LayoutInflater.from(context).inflate(
					R.layout.mine_message_item, null);

			mh.tv_title = (TextView) arg1.findViewById(R.id.tv_title);
			mh.tv_time = (TextView) arg1.findViewById(R.id.tv_time);
			mh.tv_des = (TextView) arg1.findViewById(R.id.tv_des);
			mh.iv_01 = (ImageView) arg1.findViewById(R.id.iv_01);
			mh.rlt_02 = (RelativeLayout) arg1.findViewById(R.id.rlt_02);
			mh.rlt_01 = (RelativeLayout) arg1.findViewById(R.id.rlt_01);

			arg1.setTag(mh);
		} else {
			mh = (Myhold) arg1.getTag();
		}

		if (type >= 1) {
			mh.rlt_02.setVisibility(View.GONE);
		}

		mh.rlt_01.setTag(mh.iv_01);
		mh.rlt_01.setOnClickListener(new OnClickListener() {

			@SuppressLint("NewApi")
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ImageView layout = (ImageView) v.getTag();
				mh.tv_des = (TextView) v.findViewById(R.id.tv_des);

				if (mh.tv_des.getMaxLines() == 99) {
					layout.setBackgroundResource(R.drawable.xia);
					mh.tv_des.setMaxLines(2);
				} else {
					layout.setBackgroundResource(R.drawable.shang);
					mh.tv_des.setMaxLines(99);
				}
			}
		});

		return arg1;
	}

	class Myhold {
		RelativeLayout rlt_02, rlt_01;
		ImageView iv_01;
		TextView tv_title, tv_time, tv_des;
	}

}
